package com.bw.base.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object Retrofituitl {
    val Client by lazy {
        OkHttpClient.Builder()
            .readTimeout(30,TimeUnit.SECONDS)
            .connectTimeout(30,TimeUnit.SECONDS)
            .writeTimeout(30,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                val token = SPUtils.getInstance().getString("token")
                val request = it.request().newBuilder().addHeader("token", token)
                    .addHeader("accessId", "b9f825b3a0f0465f9bc388e2fec30e46").build()
                it.proceed(request)
            }
            .build()

    }
    val Reforfit by lazy {
        Retrofit.Builder()
            .client(Client)
            .baseUrl(Const.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
}